package com.sgb.kjwl.view.ui.activity.enterprise;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityIntellpropDetailBinding;
import com.sgb.kjwl.di.enterprise.DaggerEnterpriseComponent;
import com.sgb.kjwl.di.enterprise.EnterpriseModule;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopInfoActivity;
import com.sgb.kjwl.viewmodel.enterprise.IntellPropDetailModel;
import com.swgk.core.base.di.AppComponent;

import javax.inject.Inject;

import static com.swgk.core.event.EventConstant.EVENT_INTELLPROP_DETAIL_JUMP;

@Deprecated
public class IntellpropDetailActivity extends AppActivity {

    @Inject
    IntellPropDetailModel viewModel;

    private ActivityIntellpropDetailBinding binding;
    boolean userFocusCompanyStatus;


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerEnterpriseComponent.builder().appComponent(appComponent)
                .enterpriseModule(new EnterpriseModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context, String typeIntellprop) {
        Intent intent = new Intent();
        intent.putExtra("typeIntellprop", typeIntellprop);
        intent.setClass(context, IntellpropDetailActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_intellprop_detail);
        String typeIntellprop = getIntent().getStringExtra("typeIntellprop");
        binding.include.ivBack.setVisibility(View.VISIBLE);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.tvGz.setOnClickListener(this);
        binding.tvChatBusiness.setOnClickListener(this);
        binding.tvEnterpriseName.setOnClickListener(this);
        switch (typeIntellprop) {
            case "商标":
                binding.include.titleView.setText("商标详情");
                binding.detailType.setText("商标详情");
                binding.tag1.setVisibility(View.VISIBLE);
                binding.tag2.setVisibility(View.VISIBLE);
                binding.tagName1.setText("使用范围");
                binding.tagName2.setText("创意说明");
                binding.detailLineTop3.setVisibility(View.GONE);
                binding.detailLineBottom3.setVisibility(View.GONE);
                break;
            case "版权":
                binding.include.titleView.setText("版权详情");
                binding.detailType.setText("版权详情");
                binding.tag1.setVisibility(View.VISIBLE);
                binding.tag2.setVisibility(View.GONE);
                binding.tagName1.setText("版权简介");
                binding.detailLineTop3.setVisibility(View.VISIBLE);
                binding.detailLineBottom3.setVisibility(View.VISIBLE);

                binding.key1.setText("版权分类");
                binding.key2.setText("授权方式");
                binding.key3.setText("授权期限");
                binding.key4.setText("著作权人");
                binding.key5.setText("登记号");
                binding.key6.setText("作者");
                break;
            case "专利":
                binding.include.titleView.setText("专利详情");
                binding.detailType.setText("专利详情");
                binding.tag1.setVisibility(View.VISIBLE);
                binding.tag2.setVisibility(View.GONE);
                binding.tagName1.setText("专利说明");
                binding.detailLineTop3.setVisibility(View.VISIBLE);
                binding.detailLineBottom3.setVisibility(View.VISIBLE);

                binding.key1.setText("行业分类");
                binding.key2.setText("专业分类");
                binding.key3.setText("专利状态");
                binding.key4.setText("申请时间");
                binding.key5.setText("过期时间");
                binding.key6.setText("联系人");
                break;
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_gz:
                if (DialogHelper.checkLogin()) {
                    viewModel.userFocusCompany("shopId");
                } else {
                    DialogHelper.showLoginDialog(this,EVENT_INTELLPROP_DETAIL_JUMP);
                }
                break;
            case R.id.tv_chat_business://联系商家
                if (DialogHelper.checkLogin()) {
                    DialogHelper.showDialog(this, "确认呼叫", "", "确定", new DialogFunction() {
                        @Override
                        public void normalRoundDialog() {
                            ActivityJump.jumpToPhone(IntellpropDetailActivity.this, "18011590242");
                        }
                    });
                } else {
                    DialogHelper.showLoginDialog(this,EVENT_INTELLPROP_DETAIL_JUMP);
                }
                break;
            case R.id.tv_enterprise_name://进入企业
                ActivityJump.jumpToActivity(this, ShopInfoActivity.class, Pair.create("id", ""),
                        Pair.create("companyNo", ""), Pair.create("position", ""), Pair.create("childPosition", ""));
                break;
        }
    }


    public void setUserFocusCompanyStatus() {
        setUserFocusCompanyStatus(!userFocusCompanyStatus);
    }

    public void setUserFocusCompanyStatus(boolean data) {
        if (data) {
            binding.tvGz.setBackgroundResource(R.drawable.bgg_lg);
            binding.tvGz.setTextColor(getResources().getColor(R.color.alertdialog_gray));
            binding.tvGz.setText("已关注");
        } else {
            binding.tvGz.setBackgroundResource(R.drawable.bgw_lb);
            binding.tvGz.setText("关注");
            binding.tvGz.setTextColor(getResources().getColor(R.color.alertdialog_blue));
        }
        userFocusCompanyStatus = data;
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
}
